#include "stdafx.h"
#include <serialization/ioParamStructs.h>
#include <serialization/serialization.h>
#include <winsock/winsock_stub.h>

void WSACleanup_stub (
    __in  std::vector<char>& in_buf,
    __out std::vector<char>& out_buf
    )
{
//RECEIVE()
    Deserialize deserialize (in_buf);
    //WSACleanup_in_inout WSACleanupIN;
    //deserialize (WSACleanupIN);

    int ret = WSACleanup ();
//SEND
    WSACleanup_out_inout WSACleanupOUT( (ret == 0) ? 0 : WSAGetLastError() );
    
    Serialize(deserialize.get_header(), WSACleanupOUT, out_buf);
}

////////////////////////////////////////////////////////////////
void __WSAFDIsSet_stub (
    __in  std::vector<char>& in_buf,
    __out std::vector<char>& out_buf
    )
{
//RECEIVE()
    Deserialize deserialize (in_buf);
    __WSAFDIsSet_in_inout __WSAFDIsSetIN;
    deserialize (__WSAFDIsSetIN);

    int ret = __WSAFDIsSet (__WSAFDIsSetIN.fd_, __WSAFDIsSetIN.set_);
//SEND
    __WSAFDIsSet_out_inout __WSAFDIsSetOUT( ret, WSAGetLastError() );
    
    Serialize(deserialize.get_header(), __WSAFDIsSetOUT, out_buf);
}

////////////////////////////////////////////////////////////////
void WSAGetLastError_stub (
    __in  std::vector<char>& in_buf,
    __out std::vector<char>& out_buf
    )
{
//RECEIVE()
    Deserialize deserialize (in_buf);
    //WSAGetLastError_in_inout WSAGetLastErrorIN;
    //deserialize (WSAGetLastErrorIN);

    int ret = WSAGetLastError ();
//SEND
    WSAGetLastError_out_inout WSAGetLastErrorOUT( ret );
    
    Serialize(deserialize.get_header(), WSAGetLastErrorOUT, out_buf);
}

////////////////////////////////////////////////////////////////
void WSASetLastError_stub (
    __in  std::vector<char>& in_buf,
    __out std::vector<char>& out_buf
    )
{
//RECEIVE()
    Deserialize deserialize (in_buf);
    WSASetLastError_in_inout WSASetLastErrorIN;
    deserialize (WSASetLastErrorIN);

    WSASetLastError (WSASetLastErrorIN.ret_);
//SEND
    WSASetLastError_out_inout WSASetLastErrorOUT;
    Serialize(deserialize.get_header(), WSASetLastErrorOUT, out_buf);
}

////////////////////////////////////////////////////////////////
void WSAStartup_stub (
    __in  std::vector<char>& in_buf,
    __out std::vector<char>& out_buf
    )
{
//RECEIVE()
    Deserialize deserialize (in_buf);
    WSAStartup_in_inout WSAStartupIN;
    deserialize (WSAStartupIN);

    WSADATA Data;
    int ret = WSAStartup (WSAStartupIN.wVersionRequested_, &Data);
//SEND
    WSAStartup_out_inout WSAStartupOUT (ret, Data);
    Serialize(deserialize.get_header(), WSAStartupOUT, out_buf);
}

